unit fpstructs;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, md5, IniFiles;

type
  TSQLEvent = procedure(Sender: TObject; SQL: string) of object;

  TJulianDateTime = Double;

  TfpMessage = (fpmNone,
                fpmRegisterTerminal,
                fpmTerminalLogon,
                fpmTerminalLogoff,
                fpmStaffLogon,
                fpmStaffLogoff,
                fpmRegisterSale,
                fpmRegisterRefund,
                fpmRequestConfigData,
                fpmSubmitConfigData,
                fpmRequestSalesData,
                fpmRequestShiftData,
                fpmRequestReport,
                fpmSQLQuery,
                fpmQueryResult,
                fpmPDFReport,
                fpmExecSQL,
                fpmConfirm);
  TfpDatatype = (fpdNone,
                fpdTimeout,
                fpdPort,
                fpdTerminalID,
                fpdSQL,
                fpdSQLUpdate,
                fpdProductList,
                fpdProductRef,
                fpdNewProduct,
                fpdProfileList,
                fpdProfileRef,
                fpdShiftReport);

  tfpHeader = record
    ID:          string[4];    // Should always be FPOS
    TerminalID:  integer;
    MessageID:   integer;
    MessageType: TfpMessage;
    datalength:  integer;
    datatype:    TfpDatatype;
    md5:         TMDDigest;
  end;

  TfpSaleSummary = record
    SaleID: integer;
    TerminalID: integer;
    SaleTime: double;
    ItemCount: integer;
    Total: single;
    StaffID: integer;
    LineCount: integer;
  end;

  TfpSaleline = record
    SaleID: integer;
    ItemID: integer;
    quantity: integer;
    price: single;
    refund: Boolean;
  end;

  TfpProduct = record
    id: integer;
    barcode: string[16];
    name: string[32];
    costprice: single;
    saleprice: single;
    taxcode: integer;
    suppliercode: integer;
    stocklevel: integer;
    dept: integer;
    discount: integer;
  end;

  TfpProfile = record
    name: string[16];
    description: string[255];
    pagecount: integer;
    buttoncount: integer;
  end;

  TfpPage = record
    id: integer;
    title: string[24];
    visible: integer;
  end;

  TfpButton = record
    id: integer;
    product: integer;
    pagenum: integer;
    top: integer;
    left: integer;
    width: integer;
    height: integer;
    visible: integer;
  end;

  TShiftInfo = record
    StaffID: integer;
    StaffName: string;
    StaffPriv: integer;
    StaffHash: String;
    StartTime: TJulianDateTime;
    StartSale: integer;
    StartCash: single;
    ReceivedCash: single;
  end;

  TfpDept = record
    id: integer;
    name: string;
  end;

  TfpSupplierInfo = record
    id: integer;
    name: string;
    address: string;
    postcode: string;
    telephone: string;
    email: string;
    contact: string;
    notes: string;
    website: string;
    accountnum: string;
  end;

  TProductArray = Array of TfpProduct;


const
  DEFAULT_PORT = 15445;
  DEF_ADMIN_PORT   = 15400;

  SERVER_ID = 0;
  ADMIN_ID = 9999;

  HEADER_ID = 'FPOS';

  SALEREGISTER = 'sales.dat';
  EVENTLOG     = 'events.dat';
  SHIFT_LOCK   = 'fposterm-lock.tmp';
  DEFAULT_PROFILE = 'default.profile';
  SYSTEM_CONFIG = 'system.dat';

  DEFAULT_MIN = '100001';
  DEFAULT_MAX = '999999';
  DEFAULT_TIMEOUT = 5000;
  MAX_SERVICEID = 999;

  CLASSMAX = 3;

  VAT_RATE = 0.2;

  FIREPOS_INFO = 'FirePOS Point of Sale';

const
  MARKUP = 2.35;

Var
  Settings: TIniFile;

function NewHeader( termID: integer; messagetype: TfpMessage; datatype: TfpDatatype=fpdNone ): tfpHeader;


implementation

function NewHeader ( termID: integer; messagetype: TfpMessage; datatype: TfpDatatype=fpdNone ) : tfpHeader;
var
  h: tfpHeader;
begin
  h.ID := HEADER_ID;
  h.TerminalID := termID;
  h.MessageID := -1;
  h.MessageType := messagetype;
  h.datalength := 0;
  h.datatype := datatype;
  Result := h
end;

end.

